<!DOCTYPE html>
<html lang="zh-cmn-Hans" xmlns:th="http://www.thymeleaf.org">

<head th:replace="base/layout::header( ~{::title})">
    <title id="title">人员工时详情</title>
</head>
<body>
<div class="ui main container">
    <div class="ui clearing segment">
        <h3 class="ui header">人员工时详情</h3>
    </div>

    <!--模态框-->
    <div class="ui small modal">
        <i class="close icon"></i>
        <div class="content">
            确认导出列表？
        </div>
        <div class="actions">
            <div class="ui cancel button">取消</div>
            <div class="ui red approve button">确定</div>
        </div>
    </div>

    <div style="overflow: auto">
        <table class="ui single line striped celled selectable table">
            <thead>
            <tr>
                <th>
                    <div class="ui checkbox">
                        <input type="checkbox" id="isSum">
                        <label>是否需要合并</label>
                        <input type="hidden" id="userKey" name="userKey" th:value="${userKey}">
                        <input type="hidden" id="isSumid" name="isSum" th:value="${isSum}">
                    </div>
                </th>
                <th colspan="9">
                    <button class="ui red button"
                            type="button" onclick="confirmExport();" style="margin-right: 20px">导出
                    </button>
                    <a class="ui grey button" th:href="@{/basicInfo/personal}">返回</a>
                </th>
            </tr>
            <tr>
                <th>人员</th>
                <th>编号</th>
                <th>项目</th>
                <th>模块</th>
                <th>标题</th>
                <th>任务类型</th>
                <th>状态</th>
                <th>创建时间</th>
                <th>工时（小时）</th>
            </tr>
            </thead>
            <tbody th:if="${pageInfo}" id="data">
            <tr th:each="detail : ${pageInfo.list}">
                <td th:text="${detail.userName}"></td>
                <td th:text="${detail.jiraNum}"></td>
                <td th:text="${detail.pName}"></td>
                <td th:text="${detail.cName}"></td>
                <td th:text="${detail.title}"></td>
                <td th:text="${detail.issueType}"></td>
                <td th:text="${detail.issueStatus}"></td>
                <td th:text="${detail.issueCreateTimeStr}"></td>
                <td th:text="${detail.timeWorked}"></td>
            </tr>
            </tbody>
        </table>
        <div th:include="base/datatable::pagination" th:remove="tag"></div>
    </div>
</div>
<div th:replace="common/footer::footer"/>
</body>

<script type="application/javascript">

    // 根据isSum的值控制是否checked
    $(function () {
        var isSumidValue = $('#isSumid').val();
        var isSumStr = isSumidValue.toString();
        if (isSumStr == '' || isSumStr == 'true') {
            $('#isSum').prop('checked', true);
        } else {
            $('#isSum').prop('checked', false);
        }
    });


    // 提交虚拟表单 模拟请求
    $('#isSum').click(function () {
        var userKey = $('#userKey').val();
        formSubmit(userKey, this.checked);
    });

    function formSubmit(userKey, isSum) {
        var turnForm = document.createElement("form");
        document.body.appendChild(turnForm);
        turnForm.method = 'post';
        turnForm.action = "/hades/basicInfo/personalDetail/" + userKey + "/" + isSum;

        //创建隐藏表单
        var userKeyElement = document.createElement("input");
        userKeyElement.setAttribute("name", "userKey");
        userKeyElement.setAttribute("type", "hidden");
        userKeyElement.setAttribute("value", userKey);
        turnForm.appendChild(userKeyElement);

        var isSumElement = document.createElement("input");
        isSumElement.setAttribute("name", "isSum");
        isSumElement.setAttribute("type", "hidden");
        isSumElement.setAttribute("value", isSum);
        turnForm.appendChild(isSumElement);

        turnForm.submit();
    }

    // 导出确认框
    function confirmExport() {
        $('.ui.small.modal')
            .modal('show')
            .modal({
                closable: false,
                onApprove: function () {
                    var userKey = $('#userKey').val();
                    var isSum = $('#isSumid').val();
                    window.location.href = "/hades/basicInfo/personalDetailExport/" + userKey + "/" + isSum;
                }
            })
        ;
    }

</script>
</html>